package com.portal.annotation.aspect;

import com.portal.annotation.annotation.AutoLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Aspect;

/**
 * 日志切面处理类
 *
 * @author Amadeus
 * @date 2022/09/08
 */
@Slf4j
@Aspect
@Component
public class LogAspect {

    @Pointcut("execution(* com.portal.annotation.controller..*.*(..)))")
    public void webLog() {
        log.info("日志切面注入");
    }

    /**
     * 定义增强，pointcut连接点使用@annotation（xxx）进行定义
     * around 与 下面参数名around对应
     *
     * @param point  点
     * @throws Throwable throwable
     */
    @Around("webLog()")
    public void processAuthority(ProceedingJoinPoint point) throws Throwable {
        log.info("ANNOTATION welcome");
        log.info("ANNOTATION 调用方法：" + point.getSignature().getName());
        log.info("ANNOTATION 调用类：" + point.getSignature().getDeclaringTypeName());
        log.info("ANNOTATION 调用类名" + point.getSignature().getDeclaringType().getSimpleName());
        point.proceed(); //调用目标方法
        log.info("ANNOTATION login success");
    }

}
